#include"share.hpp"

int main()
{
    //创建管道
    FIFO init;

    int fd = open("myfifo",O_RDONLY);
    if(fd == -1)
    {
        log(error,"open failure: %s",strerror(errno));
        exit(5);
    }

    //创建共享内存
    int shmid = CreateShmid();

    //建立链接
    char* shmaddr = (char*)shmat(shmid,nullptr,0);
    if((void*)shmaddr == (void*)-1)
    {
        log(fatal,"shamt failure: %s",strerror(errno));
        return 1;
    }

    
    //进行通信
    while(true)
    {
        char ch;
        int n = read(fd,&ch,sizeof(char));
        if(n == 0) break;
        else if(n < 0) break;

        std::cout << "client say@ " << shmaddr << std::endl;
        sleep(1);
    }

    //解挂接
    shmdt((void *)shmaddr);
    sleep(5);
    
    //删除共享内存
    DeleteShare(shmid);
    return 0;
}
